<!doctype html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
  <link href="/static/css/jquery-rvnm.css" rel="stylesheet">
  <title>全国城市天气</title>
</head>
<body>
  <header>
  {% include "navbar.html" %}
  </header>

  <main style="margin-top: 50px; padding: 20px; position: relative">
    {% for m in messages %}
      <div class="alert alert-{{ m.extra_tags }} alert-dismissable" role="alert" style="position: absolute; left: 0; top: 0; z-index: 999; width: 100%">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
        <span>{{ m }}</span>
      </div>
    {% endfor %}
    <nav id="navbar">
      <ul>
      {% for r in region_list %}
        <li>
        {% if r.is_municipality %}
          <a href="/region/{{ r.id }}">
            {{ r.name }}
          </a>
        {% else %}
          <a href="#">
            {{ r.name }}
          </a>
          <ul>
          {% for r1 in r.children.all %}
            <li>
              <a href="/region/{{ r1.id }}">
                {{ r1.name }}
              </a>
            </li>
          {% endfor %}
          </ul>
        {% endif %}
        </li>
      {% endfor %}
      </ul>
    </nav>

    <div style="position: fixed; left: 270px; top: 70px; width: 80%">
      <h3 class="text-primary">
      {% if region.is_municipality %}
        {{ region.name }}
      {% else %}
        {{ region.get_province_name }} {{ region.name }}
      {% endif %}
        <a href="#" class="small" data-toggle="modal" data-target="#exampleModal">[编辑城市]</a>
      </h3>

      <div>
      {% if region.latitude and region.longitude %}
        <span class="label label-primary">北纬: {{ region.latitude }}</span>
        <span class="label label-primary">东经: {{ region.longitude }}</span>
      {% endif %}
      {% if region.is_display %}
      <span class="label label-warning">在地图上展示</span>
      {% endif %}
      {% if region.is_province_capital %}
      <span class="label label-success">省会城市</span>
      {% endif %}
      {% if region.is_municipality %}
      <span class="label label-success">直辖市</span>
      {% endif %}
      </div>

      <h4 style="margin-top: 20px">城市7日天气预报</h4>

      <table class="table table-striped table-hover">
        <thead>
        <tr>
          <td>日期</td>
          <td>天气</td>
          <td>最高温</td>
          <td>最低温</td>
          <td>风向</td>
          <td>风力</td>
        </tr>
        </thead>
        <tbody>
        {% for d in data %}
          <tr>
            <td>{{ d.time }}</td>
            <td>{{ d.day_weather }}</td>
            <td>{{ d.max_degree }}</td>
            <td>{{ d.min_degree }}</td>
            <td>{{ d.day_wind_direction }}</td>
            <td>{{ d.day_wind_power }}</td>
          </tr>
        {% endfor %}
        </tbody>
      </table>
    </div>
  </main>

  <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" id="exampleModalLabel">编辑城市: {{ region.name }}信息</h4>
        </div>
        <div class="modal-body">
          <form action="/region/{{ region.id }}" method="post">
          {% csrf_token %}
            <div class="form-group">
              <label class="control-label">纬度:</label>
              <input type="text" class="form-control" name="latitude" value="{{ region.latitude }}">
            </div>
            <div class="form-group">
              <label class="control-label">经度:</label>
              <input type="text" class="form-control" name="longitude" value="{{ region.longitude }}">
            </div>
            <div class="form-group">
              <label class="control-label">是否在地图上展示:</label>
              <input type="checkbox" name="is_display" {% if region.is_display %}checked{% endif %} >
            </div>

            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
              <button type="submit" class="btn btn-primary">保存信息</button>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>

  <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
  <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
  <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
  <script src="/static/js/jquery-rvnm.js"></script>
  <script>
    $(function () {
      let rvnMenu = $("#navbar").rvnm({
        // mode: 'mobile',
        // responsive: false,
        searchable: true,
        theme: 'dark-lesb'
      });
      console.log(rvnMenu);
      // rvnMenu.setMode('minimal');
      rvnMenu.setTheme('dark-ruby');
    });
  </script>
</body>
</html>